# Copyright (c) Zhirnov Andrey. For more information see 'LICENSE'
#
# download GLSLANG (BSD-like license)

set( GLSLANG_PATH "${AE_DST_PATH}/glslang" )

add_library( "GLSLang-lib" INTERFACE )
target_include_directories( "GLSLang-lib" INTERFACE "${GLSLANG_PATH}/include" )
target_compile_definitions( "GLSLang-lib" INTERFACE "AE_ENABLE_GLSLANG" "ENABLE_OPT" "AE_LICENSE_BSD" )

install( FILES "${GLSLANG_PATH}/glslang-LICENSE.txt" DESTINATION "3party_license" RENAME "glslang-LICENSE" )
install( FILES "${GLSLANG_PATH}/SPIRV-Tools-LICENSE.txt" DESTINATION "3party_license" RENAME "SPIRV-Tools-LICENSE" )
install( FILES "${GLSLANG_PATH}/SPIRV-Headers-LICENSE.txt" DESTINATION "3party_license" RENAME "SPIRV-Headers-LICENSE" )

# with debug libs
set_property( TARGET "GLSLang-lib" PROPERTY INTERFACE_LINK_LIBRARIES
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools-opt${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glslang${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}MachineIndependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}OSDependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Release>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}GenericCodeGen${CMAKE_STATIC_LIBRARY_SUFFIX}" >

	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools-opt${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glslang${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}MachineIndependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}OSDependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Profile>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}GenericCodeGen${CMAKE_STATIC_LIBRARY_SUFFIX}" >

	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools-opt${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glslang${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}MachineIndependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}OSDependent${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Develop>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}GenericCodeGen${CMAKE_STATIC_LIBRARY_SUFFIX}" >

	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRVd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Tools-optd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}SPIRV-Toolsd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}glslangd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}MachineIndependentd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}OSDependentd${CMAKE_STATIC_LIBRARY_SUFFIX}" >
	$<$<CONFIG:Debug>: "${GLSLANG_PATH}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}GenericCodeGend${CMAKE_STATIC_LIBRARY_SUFFIX}" >
)

if (${AE_ENABLE_EXTERNAL_TESTS})
	add_executable( "Tests.GLSLang" "tests/main.cpp" )
	set_property( TARGET "Tests.GLSLang" PROPERTY FOLDER "Engine/External/Tests" )
	target_link_libraries( "Tests.GLSLang" PUBLIC "GLSLang-lib" )
	#add_test( NAME "Tests.GLSLang" COMMAND "Tests.GLSLang" )
	set_target_properties( "Tests.GLSLang" PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES )
endif ()
